home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / winlib-0.0 / winlib-0 / win / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-02  |  3.9 KB  |  205 lines

  1. /*
  2.  * Windowing Library
  3.  * Initialization routines
  4.  */
  5.  
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <netdb.h>
  9. #include <sys/socket.h>
  10. #include <sys/types.h>
  11. #include <netinet/in.h>
  12. #include <arpa/inet.h>
  13.  
  14. #include "winlib.h"
  15. #include "internal.h"
  16. #include "config.h"
  17.  
  18. WINDOW *_main_win, *_menu_win, *_menu_area;
  19. PANEL *_main_pan, *_menu_pan, *_menu_area_pan;
  20. MENU *_menutree;
  21. void (*_keydispatch)(), (*_mousedispatch)();
  22. int _cur_title, _showing_menu, _cur_window, _xoffset, _sound_socket,
  23.     _sound_init, _resizing_win, _resize_corner;
  24.  
  25. /* Set keyboard callback routine */
  26. void Win_SetCallbackKEYBOARD(void *routine)
  27. {
  28.     _keydispatch = (routine == NULL) ? NULL : routine;
  29. }
  30.  
  31. /* Set mouse callback routine */
  32. void Win_SetCallbackMOUSE(void *routine)
  33. {
  34.     _mousedispatch = (routine == NULL) ? NULL : routine;
  35. }
  36.  
  37. /* Report back the current library version */
  38. char *Win_GetLibraryVersion(void)
  39. {
  40.     return(WINLIB_VERSION);
  41. }
  42.  
  43. int Win_GetOptions(void)
  44. {
  45.     int x;
  46.  
  47.     x = 0;
  48.  
  49. #ifdef    DEBUG
  50.     x |= OPT_DEBUG;
  51. #endif
  52.  
  53. #ifdef    MOUSE_COORD
  54.     x |= OPT_MOUSECOORD;
  55. #endif
  56.  
  57. #ifdef    COLOR_SUPPORT
  58.     x |= OPT_COLOR;
  59. #endif
  60.  
  61. #ifdef    SOUND_SUPPORT
  62.     x |= OPT_SOUND;
  63. #endif
  64.  
  65. #ifdef    WAVFILE
  66.     x |= OPT_WAVFILE;
  67. #endif
  68.  
  69. #ifdef    USE_DEV_AUDIO
  70.     x |= OPT_USEDEVAUDIO;
  71. #endif
  72.  
  73.     if (_sound_init)
  74.     x |= OPT_SOUNDINIT;
  75.  
  76.     return(x);
  77. }
  78.  
  79. /* Initialize NCURSES code */
  80. void Win_InitializeNCURSES(void)
  81. {
  82.     if (initscr() != NULL) {
  83.     start_color();
  84.     cbreak();
  85.     noecho();
  86.     nonl();
  87.     scrollok(stdscr, FALSE);
  88.     keypad(stdscr, TRUE);
  89.     refresh();
  90.     } else {
  91.     printf("WinLIB: Cannot initialize ncurses library!\n");
  92.     fflush(stdout);
  93.     exit(0);
  94.     }
  95. }
  96.  
  97. /* Initialize GPM cruft.  This is basic code, and was used in the standard
  98.    GPM library and demo programs. */
  99. void Win_InitializeGPM(void)
  100. {
  101.     Gpm_Connect conn;
  102.  
  103.     conn.eventMask = ~0;
  104.     conn.defaultMask = ~GPM_HARD;
  105.     conn.maxMod = ~0;
  106.     conn.minMod = 0;
  107.  
  108.     if (Gpm_Open(&conn, 0) < 0) {
  109.     printf("WinLIB: Cannot initialize GPM library! (First connect)\n");
  110.     fflush(stdout);
  111.     exit(0);
  112.     }
  113.  
  114.     Gpm_Close();
  115.  
  116.     gpm_zerobased = 1;
  117.     gpm_visiblepointer = 1;
  118.  
  119.     if (Gpm_Open(&conn, 0) < 0) {
  120.     printf("WinLIB: Cannot initialize GPM library! (Second connect)\n");
  121.     fflush(stdout);
  122.     exit(0);
  123.     }
  124.  
  125.     /* Don't forget to set the library handler! */
  126.     gpm_handler = Win_LibHandler;
  127. }
  128.  
  129. void Win_InitializeVARIABLES(void)
  130. {
  131.     _has_menu = FALSE;
  132.     _has_win = FALSE;
  133.     _cur_title = 0;
  134.     _cur_item = -1;
  135.     _cur_window = 0;
  136.     _xoffset = 0;
  137.     _sound_init = 0;
  138.     _moving_idx = -1;
  139.     _resize_corner = 0;
  140.     _showing_menu = FALSE;
  141.     _changed = FALSE;
  142.     _moving_win = FALSE;
  143.     _resizing_win = FALSE;
  144.     _keydispatch = NULL;
  145.     _mousedispatch = NULL;
  146.     _open_sound = NULL;
  147.     _close_sound = NULL;
  148.     _destroy_sound = NULL;
  149.     _min_sound = NULL;
  150.     _max_sound = NULL;
  151.  
  152.     _menutree = (MENU *) malloc(_menustruct_length());
  153.     _menutree->prev = NULL;
  154.     _menutree->next = NULL;
  155.  
  156.     _wintree = (WIN *) malloc(_winstruct_length());
  157.     _wintree->prev = NULL;
  158.     _wintree->next = NULL;
  159.  
  160.     _main_win = newwin(stdscr->_maxy, stdscr->_maxx + 1, 1, 0);
  161.     _main_pan = new_panel(_main_win);
  162.  
  163.     scrollok(_main_win, TRUE);
  164. }
  165.  
  166. int Win_Initialize(void)
  167. {
  168.     Win_InitializeNCURSES();
  169.     Win_InitializeGPM();
  170.     Win_InitializeVARIABLES();
  171.  
  172.     return(TRUE);
  173. }
  174.  
  175. int Win_InitializeSound(void)
  176. {
  177.     struct protoent *p;
  178.     struct sockaddr_in sin;
  179.  
  180.     bzero((char *) &sin, sizeof(sin));
  181.     sin.sin_family = AF_INET;
  182.     sin.sin_port = htons(8000);
  183.     sin.sin_addr.s_addr = inet_addr(SOUND_ADDRESS);
  184.  
  185.     p = getprotobyname("tcp");
  186.     if ((_sound_socket = socket(AF_INET, SOCK_STREAM, p->p_proto)) < 0)
  187.     return(FALSE);
  188.  
  189.     if (connect(_sound_socket, (struct sockaddr *) &sin, sizeof(sin)) < 0)
  190.     return(FALSE);
  191.  
  192.     tcdrain(_sound_socket);
  193.  
  194.     _sound_init = 1;
  195.     return(TRUE);
  196. }
  197.  
  198. void Win_Deinitialize(void)
  199. {
  200.     Win_PlaySound(SOUND_EXIT);
  201.     erase();
  202.     refresh();
  203.     endwin();
  204. }
  205.